package org.finesys.common.log.trace.processor;

import io.lettuce.core.api.sync.RedisCommands;
import org.finesys.common.log.trace.interceptor.redis.SpringRedisCommandInterceptor;
import org.finesys.common.log.trace.util.ProxyUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * lettuce代理
 */
public class LettuceCorePostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof RedisCommands) {
            return ProxyUtil.getProxy(bean, new SpringRedisCommandInterceptor());
        }
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
